package com.fcat.gateway.model;

/**
 * @description 下发状态枚举类
 */
public enum StateCode {

    SUCCESS_SERVICE(0, "成功"),
    SYSTEM_EXCEPTION(-1, "系统异常"),
//    HEADER_NOUSERNAME(-2, "request header 'username' is not present"),
//    NO_TOKEN(401, "token is empty"),
//    INVALID_TOKEN(-401, "token is invalid"),
//    INVALID_TOKEN2(-402, "token is invalid, timeout"),
//    INVALID_TOKEN3(-403, "token is invalid, crowded"),
    HEADER_NOUSERNAME(-2, "请求头的 'username' 不能为空"),
    NO_TOKEN(401, "请求头的 token 不能为空"),
    INVALID_TOKEN(-401, "授权token无效或过期(keycloak)"),
//    INVALID_TOKEN2(-402, "token 超时，授权token无效"),
//    INVALID_TOKEN3(-403, "token 无效,被其他用户挤掉"),
    INVALID_TOKEN2(-402, "登录账户连接过期，需重新登录"),
    INVALID_TOKEN3(-403, "该账户在其他客户端电脑登录，请确认账户信息是否安全"),
    ;

    int code;

    String msg;

    StateCode(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static StateCode get(int code){
        for(StateCode stateCode : values()){
            if(stateCode.getCode() == code){
                return stateCode;
            }
        }
        return SYSTEM_EXCEPTION;
    }

    public static StateCode get(String msg){
        for(StateCode stateCode : values()){
            if(stateCode.getMsg().equalsIgnoreCase(msg)){
                return stateCode;
            }
        }
        return SYSTEM_EXCEPTION;
    }
}
